import requests
from util.font import get_font_maps

def get_font_file():
    font_path="./static/font/dcd.ttc"
    font_url = 'https://lf6-awef.bytetos.com/obj/awesome-font/c/96fc7b50b772f52.woff2'
    response = requests.get(font_url)
    print(response)
    with open(font_path, "wb") as f:
        f.write(response.content)
    return font_path



def parse_filed(value, font_maps):
    font_maps = font_maps
    result = ""
    for char in value:
        if ord(char) in font_maps:
            result += font_maps[ord(char)]
        else:
            result += char
    return result



url = "https://www.dongchedi.com/motor/pc/sh/sh_sku_list?aid=1839&app_name=auto_web_pc"

response = requests.post(url, data={
"price":"20,-1",
"sh_city_name":"全国",
"page":"2",
"limit":"20",
})
font_maps = get_font_maps(get_font_file())
for item in response.json()["data"]["search_sh_sku_info_list"]:
    brand_name = item['brand_name']
    car_name = item['car_name']
    official_price = item['official_price']
    sh_price = item['sh_price']
    print(brand_name, car_name, parse_filed(official_price, font_maps), parse_filed(sh_price, font_maps))
